
import {useIntersectionObserver} from "@vueuse/core";

export const lazyPlugin = {
    install(app){
        // 实现懒加载
        app.directive('ima-lazy',{
            // el:绑定的元素 binding:绑定的值
            // key-value
            mounted(el,binding){
                const {stop} = useIntersectionObserver(
                    el,
                    ([{isIntersecting}])=>{
                        if(isIntersecting){
                            el.src = binding.value
                            // 只进行一次渲染
                            stop()
                        }
                    }
                )
            }
        })
    }
}